package ysq.xyg.sale.controller;

import ysq.xyg.base.aspect.BaseLog;
import ysq.xyg.base.util.BaseConstant;

import cn.hutool.core.util.StrUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import ysq.xyg.base.aspect.BaseLog;
import ysq.xyg.base.controller.BaseController;
import ysq.xyg.base.util.BaseConstant;
import ysq.xyg.base.model.dto.ReturnEntity;
import ysq.xyg.sale.model.po.SaleRecord;
import ysq.xyg.sale.model.vo.SaleRecordVo;
import ysq.xyg.sale.service.SaleRecordService;
import ysq.xyg.sys.model.po.SysUser;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 销售模块-流水记录controller层
 *
 * @author shengQiang yu
 * @date 2019-9-24 16:02:37
 */
@RestController
public class SaleRecordController extends BaseController {

    private static Logger log= LoggerFactory.getLogger(SaleRecordController.class);
    @Resource
    private SaleRecordService saleRecordService;

    private SaleRecord saleRecord;
    /**
     * 管理员充值费用
     *
     * @param userId 充值对象id
     * @param money 充值金额
     * @param request
     * @return ReturnEntity 对象
     * @author shengQiang yu
     * @date 2019-9-9 14:17:04
     */
    @BaseLog(module = "销售模块",className = "流水记录",methods = "管理员充值费用",businessType = BaseConstant.SYS_BUSINESS_TYPE_INSERT,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/saleRecord/managerAddMoney",method = RequestMethod.POST)
    public ReturnEntity managerAddMoney(HttpServletRequest request, String userId,Double money){
        ReturnEntity returnEntity = saleRecordService.managerAddMoney(userId,money,acceptCurrentUser(request));
        return returnEntity;
    }
    /**
     * 上级代理充值费用
     *
     * @param userId 充值对象id
     * @param money 充值金额
     * @param request
     * @return ReturnEntity 对象
     * @author shengQiang yu
     * @date 2019-9-9 14:17:04
     */
    @BaseLog(module = "销售模块",className = "流水记录",methods = "上级代理充值费用",businessType = BaseConstant.SYS_BUSINESS_TYPE_INSERT,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/saleRecord/parentAddMoney",method = RequestMethod.POST)
    public ReturnEntity parentAddMoney(HttpServletRequest request, String userId,Double money){
        ReturnEntity returnEntity = saleRecordService.parentAddMoney(request,userId,money,acceptCurrentUser(request));
        return returnEntity;
    }
    /**
     * 分页查询
     *
     * @param saleRecordVo 对象
     * @param pageSize 展示数量
     * @param pageNum 当前页面
     * @author shengQiang yu
     * @date 2019-9-24 16:02:37
     */
    @BaseLog(module = "销售模块",className = "流水记录",methods = "分页查询",businessType = BaseConstant.SYS_BUSINESS_TYPE_GET,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/saleRecord/page",method = RequestMethod.POST)
    public ReturnEntity page(SaleRecordVo saleRecordVo, int pageSize, int pageNum){
        ReturnEntity returnEntity = saleRecordService.page(saleRecordVo,pageSize,pageNum);
        return returnEntity;
    }
    /**
     * 我的账单分页查询
     *
     * @param saleRecordVo 对象
     * @param pageSize 展示数量
     * @param pageNum 当前页面
     * @author shengQiang yu
     * @date 2019-9-24 16:02:37
     */
    @BaseLog(module = "销售模块",className = "流水记录",methods = "我的账单分页查询",businessType = BaseConstant.SYS_BUSINESS_TYPE_GET,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/saleRecord/pageByMy",method = RequestMethod.POST)
    public ReturnEntity pageByMy(HttpServletRequest request, SaleRecordVo saleRecordVo, int pageSize, int pageNum){
        SysUser sysUser=acceptCurrentUser(request);
        saleRecordVo.setUserId(sysUser.getId());
        ReturnEntity returnEntity = saleRecordService.pageByMy(saleRecordVo,pageSize,pageNum);
        return returnEntity;
    }

    /**
     * 跳转连接
     *
     * @param id 主键id
     * @author shengQiang yu
     * @date 2019-9-24 16:02:37
     */
    @RequestMapping(value = "/saleRecord/getEntity",method = RequestMethod.GET)
    public ModelAndView getEntity(String id){
        ModelAndView view = new ModelAndView("/sale/saleRecordUpdateOrSave");
        if(StrUtil.isNotEmpty(id)){
            saleRecord = saleRecordService.selectByPrimaryKey(id);
            view.addObject("saleRecord", saleRecord);
        }
        return view;
    }
    /**
     * 删除
     *
     * @param id 主键id
     * @author shengQiang yu
     * @date 2019-9-24 16:02:37
     */
    @BaseLog(module = "销售模块",className = "流水记录",methods = "删除",businessType = BaseConstant.SYS_BUSINESS_TYPE_DELETE,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/saleRecord/delete")
    public ReturnEntity delete(HttpServletRequest request,String id){
        return saleRecordService.delete(id,acceptCurrentUser(request));
    }

    /**
     * 添加或修改
     *
     * @param saleRecordVo Vo对象
     * @author shengQiang yu
     * @date 2019-9-24 16:02:37
     */
    @BaseLog(module = "销售模块",className = "流水记录",methods = "添加或修改",businessType = BaseConstant.SYS_BUSINESS_TYPE_UPDATE,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/saleRecord/addOrUpdate",method = RequestMethod.POST)
    public ReturnEntity delete(HttpServletRequest request,SaleRecordVo saleRecordVo){
        return saleRecordService.addOrUpdate(saleRecordVo,acceptCurrentUser(request));
    }
}